package com.acxy.ants.core.config;

import com.acxy.ants.common.enums.ViewType;
import com.acxy.ants.common.kit.StrKit;
import com.acxy.ants.core.Const;

import java.util.HashMap;
import java.util.Map;

/**
 * @author MrShun
 * @version 1.0
 * @Date 2017-04-27
 */
public class Constants {

    //编码集
    private String encoding = Const.DEFAULT_ENCODING;

    //是否开启调试
    private boolean debug = Const.DEFAULT_DEBUG;
    //文件上传目录
    private String baseUploadPath = Const.DEFAULT_BASE_UPLOAD_PATH;
    //文件下载目录
    private String baseDownloadPath = Const.DEFAULT_BASE_DOWNLOAD_PATH;

    //参数分隔符 为空的时候执行系统参数
    private String urlParaSeparator = Const.DEFAULT_URL_PARA_SEPARATOR;
    //模板类型
    private ViewType viewType = Const.DEFAULT_VIEW_TYPE;
    //解析文件后缀
    private String viewSuffix = Const.DEFAULT_VIEW_SUFFIX;
    //允许文件最大上传大小
    private int maxPostSize = Const.DEFAULT_MAX_POST_SIZE;
    //模板更新时间
    private int templateUpdateDelay = Const.DEFAULT_TEMPLATE_UPDATE_DELAY;    // just for not devMode


    //controller、Service、Entity 包路路径 设置此参数可以加快扫描速度
    private String controllerPackage, servicePackage, entityPackage;

    private String error404Page, error500Page;

    //设置url拦截后缀 例如.html,.json,.jsp
    private String[] regexSuffix = null;
    //设置静态目录不经过handler链
    private String[] resources = null;


    //配置模块列表可以加载多个子模块
    private String[] modules = {};

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    public boolean isDebug() {
        return debug;
    }

    public void setDebug(boolean debug) {
        this.debug = debug;
    }

    public String getBaseUploadPath() {
        return baseUploadPath;
    }

    public void setBaseUploadPath(String baseUploadPath) {
        this.baseUploadPath = baseUploadPath;
    }

    public String getBaseDownloadPath() {
        return baseDownloadPath;
    }

    public void setBaseDownloadPath(String baseDownloadPath) {
        this.baseDownloadPath = baseDownloadPath;
    }

    public String getUrlParaSeparator() {
        return urlParaSeparator;
    }

    public void setUrlParaSeparator(String urlParaSeparator) {
        this.urlParaSeparator = urlParaSeparator;
    }

    public ViewType getViewType() {
        return viewType;
    }

    public void setViewType(ViewType viewType) {
        this.viewType = viewType;
    }

    public String getViewSuffix() {
        return viewSuffix;
    }

    public void setViewSuffix(String viewSuffix) {
        this.viewSuffix = viewSuffix;
    }

    public int getMaxPostSize() {
        return maxPostSize;
    }

    public void setMaxPostSize(int maxPostSize) {
        this.maxPostSize = maxPostSize;
    }

    public int getTemplateUpdateDelay() {
        return templateUpdateDelay;
    }

    public void setTemplateUpdateDelay(int templateUpdateDelay) {
        if (templateUpdateDelay < 0) {
            throw new IllegalArgumentException("template_update_delay must more than -1.");
        }
        this.templateUpdateDelay = templateUpdateDelay;
    }

    public String getControllerPackage() {
        return controllerPackage;
    }

    public void setControllerPackage(String controllerPackage) {
        this.controllerPackage = controllerPackage;
    }

    public String getServicePackage() {
        return servicePackage;
    }

    public void setServicePackage(String servicePackage) {
        this.servicePackage = servicePackage;
    }

    public String getEntityPackage() {
        return entityPackage;
    }

    public void setEntityPackage(String entityPackage) {
        this.entityPackage = entityPackage;
    }

    public String getRegexSuffix() {
        if (regexSuffix != null && regexSuffix.length != 0) {
            StringBuffer sb = new StringBuffer("{:(");
            for (int i = 0; i < regexSuffix.length; i++) {
                sb.append(regexSuffix[i]);
                if (i != regexSuffix.length - 1)
                    sb.append("|");
            }
            sb.append(")}");
            return sb.toString();
        }
        return "";
    }

    public void setRegexSuffix(String... regexSuffix) {
        this.regexSuffix = regexSuffix;
    }

    public String[] getResources() {
        return resources;
    }

    public void setResources(String... resources) {
        this.resources = resources;
    }

    public String getError404Page() {
        return error404Page;
    }

    public void setError404Page(String error404Page) {
        this.error404Page = StrKit.setInitial(error404Page, "/");
    }

    public String getError500Page() {
        return error500Page;
    }

    public void setError500Page(String error500Page) {
        this.error500Page = StrKit.setInitial(error500Page, "/");
    }

    public String[] getModules() {
        return modules;
    }

    public void addModules(String... modules) {
        this.modules = modules;
    }
}
